package com.zhiyou100.service;

import com.zhiyou100.entity.Grade;
import com.zhiyou100.entity.Parent;
import com.zhiyou100.entity.Student;
import com.zhiyou100.entity.StudentParent;
import com.zhiyou100.mapper.GradeMapper;
import com.zhiyou100.mapper.ParentMapper;
import com.zhiyou100.mapper.StudentMapper;
import com.zhiyou100.mapper.StudentParentMapper;
import com.zhiyou100.vo.StudentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StudentVOServiceImp  implements  StudentVOService {
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private GradeMapper gradeMapper;
    @Autowired
    private ParentMapper parentMapper;
    @Autowired
    private StudentParentMapper studentParentMapper;
    @Override
    public List<StudentVO> getAllByGrade(Integer gid) {
        List<StudentVO> list=new ArrayList<>();
        Grade grade=new Grade();grade.setGid(gid);
        Grade dbGrade=gradeMapper.selectOne(grade);
        List<Student> studentList=studentMapper.getAllByGid(gid);

        for (int i = 0; i <studentList.size() ; i++) {
             StudentVO studentVO=new StudentVO();
             studentVO.setGrade(dbGrade);
             studentVO.setStudent(studentList.get(i));
             List<Parent> parentList=parentMapper.getAllBySid(studentList.get(i).getSid());
              studentVO.setParents(parentList);
              list.add(studentVO);
        }
        return list;
    }
}
